<template>
  <div>
    <n-drawer v-model:show="showModal" :width="dialogWidth">
      <n-drawer-content title="订单详情" closable>
        <n-spin :show="loading" description="请稍候...">
          <n-descriptions label-placement="left" class="py-2" column="2">
            <n-descriptions-item>
              <template #label>
                订单号
              </template>
              {{ formValue.orderSn }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                订单金额
              </template>
              {{ formValue.orderAmount }} JPY
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                订单状态
              </template>
              <n-tag
                :type="getOptionTag(options.order_status, formValue.orderStatus)"
                size="small"
                class="min-left-space"
              >
                {{ getOptionLabel(options.order_status, formValue.orderStatus) }}
              </n-tag>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                预定状态
              </template>
              <n-tag
                :type="getOptionTag(options.booking_status, formValue.bookingStatus)"
                size="small"
                class="min-left-space"
              >
                {{ getOptionLabel(options.booking_status, formValue.bookingStatus) }}
              </n-tag>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                餐厅
              </template>
              {{ formValue.restaurantDetail.name }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                套餐
              </template>
              {{ formValue.goodsDetail.goodsName }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                预订人
              </template>
              {{ formValue.bookingName }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                预订电话
              </template>
              {{ formValue.phoneArea }}{{ formValue.bookingMobile }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                预订邮箱
              </template>
              {{ formValue.bookingEmail }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                预定数
              </template>
              {{ formValue.bookingCount }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                预定时间
              </template>
              {{ formValue.bookDate }} {{ formValue.bookTime }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                用户留言
              </template>
              {{ formValue.memberMessage ? formValue.memberMessage : '--' }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                下单时间
              </template>
              {{ formValue.createdAt }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                支付时间
              </template>
              {{ formValue.payTime ? formValue.payTime : '--' }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                核销状态
              </template>

              <n-tag v-if="formValue.verifyStatus=='VERIFIED'"
                type="success"
                size="small"
                class="min-left-space"
              >
                已核销
              </n-tag>
              <n-tag v-else
                     type="warning"
                     size="small"
                     class="min-left-space"
              >
                未核销
              </n-tag>
            </n-descriptions-item>
            <n-descriptions-item v-if="formValue.verifyStatus=='VERIFIED'">
              <template #label>
                核销时间
              </template>
              {{ formValue.verifyTime }}
            </n-descriptions-item>
          </n-descriptions>


          <!-- 交易流水 -->
          <div style="padding: 20px 0" class="lh-2" v-if="formValue.transactionDetail">
            <div class="f16">交易流水</div>
            <div class="payitem" v-for="(item, index) in formValue.transactionDetail" :key="index">
              <div class="flex-row">
                <div> <span class="c333">支付流水号：</span>{{ item.transactionSn }}</div>
                <div class="flex-item text-r">
                  <span v-if="item.payStatus == 'WAIT'" class="cblue">等待支付</span>
                  <span v-else-if="item.payStatus == 'DONE'" class="csuccess">完成支付</span>
                  <span v-else-if="item.payStatus == 'CANCEL'" class="c999">取消支付</span>
                </div>
              </div>
              <div><span class="c333">第三方支付流水号：</span>{{ item.paymentRequestId }}</div>
              <div class="flex-row">
                <div><span class="c333">创建时间：</span>{{ item.createdAt }}</div>
              </div>
              <div class="flex-row">
                <div><span class="c333">过期时间：</span>{{ item.expiredTime }}</div>

                <div class="flex-item text-r">
                  {{ item.amount }} <span class="c999">{{ item.priceCurrency }} </span>
                  /
                  <span class="cwarning" style="font-size: 14px">{{ item.payAmount }}</span>
                  <span class="c999 f12">{{ item.priceCurrency }}</span>
                </div>
              </div>
              <div class="flex-row">
                <div>
                  <span class="c333">支付平台：</span>
                  <span>{{item.payChannel}}  /  {{item.payType}}</span>
                  <!--                  <span v-if="item.payChannel == 'SYSTEM'" class="cblue">系统积分</span>-->
                  <!--                  <span v-else-if="item.payChannel == 'PAYCLOUD'" class="cblue"-->
                  <!--                    >paycloud第三方支付平台-->
                  <!--                  </span>-->
                </div>
                <div class="flex-item text-r">
                  <span class="c999">
                    【总退款金额：{{ item.refundAmount }}
                    <span class="c999 f12">{{ item.priceCurrency }} </span>
                    】
                  </span>
                </div>
              </div>
            </div>
          </div>
          <!-- 退款流水 -->
          <div style="padding: 20px 0" class="lh-2" v-if="formValue.transactionRefundDetail">
            <div class="f16">退款流水</div>
            <div
              class="payitem"
              v-for="(item, index) in formValue.transactionRefundDetail"
              :key="index"
            >
              <div>
                <span class="c333">退款单号: </span>
                <span>{{ item.refundSn }}</span>
              </div>
              <div class="flex-row">
                <div>
                  <span class="c333">退款方式： </span>
                  <span>{{ item.refundType }}</span>
                </div>
                <div style="padding-left: 5px;">
                  <span class="c333">退款时间： </span>
                  <span>{{ item.refundTime ? item.refundTime : item.updatedAt }}</span>
                </div>
                <div class="text-r flex-item"
                >{{ item.refundAmount }}<span class="c999 f12">JPY</span></div
                >
              </div>
            </div>
          </div>

        </n-spin>
      </n-drawer-content>
    </n-drawer>
  </div>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue';
import { useMessage } from 'naive-ui';
import { View } from '@/api/foodOrder';
import { State, newState } from '@/views/foodOrder/model';
import {adaModalWidth, getOptionLabel, getOptionTag, Option} from '@/utils/hotgo';
import {Dicts} from "@/api/dict/dict";

const message = useMessage();
const loading = ref(false);
const showModal = ref(false);
const formValue = ref(newState(null));
const dialogWidth = computed(() => {
  return adaModalWidth(580);
});
const fileAvatarCSS = computed(() => {
  return {
    '--n-merged-size': `var(--n-avatar-size-override, 80px)`,
    '--n-font-size': `18px`,
  };
});
const options = ref({
  order_status: [] as Option[],
  booking_status: [] as Option[],
});

function openModal(state: State) {
  showModal.value = true;
  loading.value = true;
  Dicts({
    types: ['order_status','booking_status'],
  }).then((res) => {
    options.value = res;
    View({ orderSn: state.orderSn })
      .then((res) => {
        formValue.value = res;
      })
      .finally(() => {
        loading.value = false;
      });
  });
}

defineExpose({
  openModal,
});
</script>

<style lang="less" scoped>
.payitem {
  border-radius: 5px;
  padding: 5px 10px;
  line-height: 25px;
  background: #f9fbfcff;
  margin-top: 10px;
}
</style>


